package me.jayramafisher.mcsurvival;

import org.jnbt.*;

public class City {

    String name;
    int startx,starty,sizex,sizez;
    Property[] properties; 
    Property[][] property_map; //x,z coordinate order
    int min_heigth, max_heigth; //the layers players that own property can edit inclusively

    /**
    *Creates a new city.
    */

    public City(String n_name, int n_startx, int n_startz, int n_sizex, int n_sizez, int n_min_height, int n_max_heigth) {
        name = n_name;
        startx = n_startx;
        startz = n_startz;
        sizex = n_sizex;
        sizez = n_sizez;
        properties = new Property[0];
        property_map = new Property[sizez][sizez];
        min_height = n_min_height;
        max_height = n_max_height;
    }

    public City(Tag tag) {
        //TODO
    }

    public Tag serialize() {
        //TODO
    }

    /**
    *Maps a property in the city's local coordinates to each column. Returns false if the property could not be mapped.
    */

    private boolean map(int x0, int z0, int x1, int z1, Property p)
    {
        if(x0 < 0 || x0 >= sizex || x1 < 0 || x1 >= sizex ||
           z0 < 0 || z0 >= sizez || z1 < 0 || z1 >= sizez )
                return false; //out of bounds
        for(int x = x0; x <= x1; ++x) {
            for(int z=z0; z<=z1; ++z)
            {
                if(property_map[x][z] != null) return false;
            }
        }
        for(int x = x0; x <= x1; ++x) {
            for(int z=z0; z<=z1; ++z)
            {
                property_map[x][z] = p;
            }
        }
        return true;
    }
}
